/**
 * @Function 调用远程服务
 * @ProjectName credit-data-platform
 * @PackageName com.py.credit.service.impl
 * @FileName RemoteBaseServiceImpl.java
 * @Date 2018年5月16日上午10:59:42
 * @Author Min DongXv
 * @Copyright (c) 2018, 金电联行 All Rights Reserved.
 */
package com.py.credit.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.py.credit.common.logs.ExceptionLogger;
import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.constant.ApiPath;
import com.py.credit.entity.DictDetailEntity;
import com.py.credit.entity.EasyCreditLogEntity;
import com.py.credit.entity.SysUser;
import com.py.credit.service.XypjRemoteBaseService;
import com.py.framework.core.entity.SysAreaEntity;
import com.py.framework.core.entity.SysOfficeEntity;
import com.py.framework.core.entity.SysUserEntity;
import com.py.framework.core.helper.UrlHelper;
import com.py.framework.core.http.HttpAgent;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.*;

/**
 * @Function 调用远程服务
 * @ClassName RemoteBaseServiceImpl
 * @Date 2018年5月16日 上午10:59:42
 * @Author Min DongXv
 */
@Service
public class XypjRemoteBaseServiceImpl implements XypjRemoteBaseService {

    @Autowired
    private UrlHelper urlHelper;

    /**
     * @param regions
     * @return
     * @Function 通过区域ID获取区域名称对应MAP
     * @FileName RemoteBaseServiceImpl.java
     * @MethodName getAreaName
     * @Date 2018年5月16日 上午11:00:06
     * @Author Min DongXv
     */
    @Override
    public RestServiceResult<Map<String, String>> getAreaName(Set<String> regions, String jdToken) {
        Map<String, String> areaInfo = new HashMap<String, String>(1);
        RestServiceResult<Map<String, String>> areaResult = new RestServiceResult<Map<String, String>>();
        areaResult.setData(areaInfo);
        RestServiceResult<List<SysAreaEntity>> result = getAreaList(regions, jdToken);
        if (null != result && RestServiceResult.CODE_SUCCESS == result.getCode()
                && !CollectionUtils.isEmpty(result.getData())) {
            List<SysAreaEntity> areas = result.getData();
            for (SysAreaEntity area : areas) {
                if (null != area && StringUtils.isNotBlank(area.getAreaName())) {
                    areaInfo.put(String.valueOf(area.getId()), area.getAreaName());
                }
            }
        } else {
            areaResult.setCode(result.getCode());
            areaResult.setMsg(result.getMsg());
        }
        return areaResult;
    }

    /**
     * @param regions
     * @return
     * @Function 通过区域ID获取区域列表
     * @FileName RemoteBaseServiceImpl.java
     * @MethodName getAreaList
     * @Date 2018年5月16日 上午11:00:06
     * @Author Min DongXv
     */
    @Override
    public RestServiceResult<List<SysAreaEntity>> getAreaList(Set<String> regions, String jdToken) {
        String url = urlHelper.getBaseServerUrl() + ApiPath.GET_REGION_NAME_BY_ID;
        Map<String, String> params = new HashMap<String, String>(1);
        params.put("ids", StringUtils.join(regions, ","));
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, jdToken);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<List<SysAreaEntity>>>() {
            });
        } catch (Exception e) {
            RestServiceResult<List<SysAreaEntity>> areaData = new RestServiceResult<List<SysAreaEntity>>();
            areaData.setCode(RestServiceResult.CODE_UNKNOW);
            areaData.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-通过区域ID获取区域列表调用异常！(XypjRemoteBaseService#getAreaList) URL:" + url + " Params:"
                    + params.toString() + "Result:" + result, e.getMessage(), e);
            return areaData;
        }
    }

    /**
     * @param ids 用户ID
     * @return
     * @Function 通过用户ID获取用户列表
     * @FileName RemoteBaseServiceImpl.java
     * @MethodName getUsersByIds
     * @Date 2018年5月19日 下午4:44:58
     * @Author Min DongXv
     */
    @Override
    public RestServiceResult<List<SysUserEntity>> getUsersByIds(Set<Integer> ids, String jdToken) {
        String url = urlHelper.getBaseServerUrl() + ApiPath.GET_USERS_BY_IDS;
        Map<String, String> params = new HashMap<String, String>(1);
        params.put("ids", StringUtils.join(ids, ","));
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, jdToken);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<List<SysUserEntity>>>() {
            });
        } catch (Exception e) {
            RestServiceResult<List<SysUserEntity>> userData = new RestServiceResult<List<SysUserEntity>>();
            userData.setCode(RestServiceResult.CODE_UNKNOW);
            userData.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-通过用户ID获取用户列表调用异常！(XypjRemoteBaseService#getUsersByIds) URL:" + url + " Params:"
                    + params.toString() + "Result:" + result, e.getMessage(), e);
            return userData;
        }
    }

    /**
     * @param ids
     * @return
     * @Function 获取用户id和名字对应关系
     * @FileName RemoteBaseServiceImpl.java
     * @MethodName getUserName
     * @Date 2018年5月22日 上午11:06:56
     * @Author Min DongXv
     */
    @Override
    public RestServiceResult<Map<String, String>> getUserName(Set<Integer> ids, String jdToken) {
        Map<String, String> userInfo = new HashMap<String, String>(1);
        RestServiceResult<Map<String, String>> userResult = new RestServiceResult<Map<String, String>>(userInfo);
        userResult.setData(userInfo);
        RestServiceResult<List<SysUserEntity>> users = getUsersByIds(ids, jdToken);
        if (null != userResult && RestServiceResult.CODE_SUCCESS == users.getCode()
                && !CollectionUtils.isEmpty(users.getData())) {
            for (SysUserEntity user : users.getData()) {
                if (null != user && StringUtils.isNotBlank(user.getRealName())) {
                    userInfo.put(String.valueOf(user.getId()), user.getRealName());
                }
            }
        } else {
            userResult.setCode(users.getCode());
            userResult.setMsg(users.getMsg());
        }
        return userResult;
    }

    /**
     * @param tableList 数据列表
     * @param result    返回结果集
     * @param token     token
     * @param userIds   用户ID SET
     * @param idCode    列表中ID的key
     * @param nameCode  列表中name的key
     * @return
     * @Function 调用用户远程服务，进行姓名填充
     * @FileName RemoteBaseServiceImpl.java
     * @MethodName matchUserName
     * @Date 2018年5月9日 上午10:33:29
     * @Author Min DongXv
     */
    @Override
    public List<Map<String, Object>> matchUserName(List<Map<String, Object>> tableList,
                                                   RestServiceResult<List<Map<String, Object>>> result, String token, Set<Integer> userIds, String idCode,
                                                   String nameCode) {
        if (!CollectionUtils.isEmpty(userIds)) {
            // 通过用户ID获取用户名称
            RestServiceResult<Map<String, String>> userInfo = getUserName(userIds, token);
            if (RestServiceResult.CODE_SUCCESS != userInfo.getCode()) {
                result.setCode(userInfo.getCode());
                result.setMsg(userInfo.getMsg());
                return tableList;
            }
            Map<String, String> users = userInfo.getData();
            // 填充姓名信息
            for (Map<String, Object> map : tableList) {
                if (null != map) {
                    String userName = users.get(String.valueOf(map.get(idCode)));
                    if (StringUtils.isNotEmpty(userName)) {
                        map.put(nameCode, userName);
                    } else {
                        map.put(nameCode, "");
                    }
                }
            }
        }
        return tableList;
    }
    
    /**
     * @param tableList 数据列表
     * @param result    返回结果集
     * @param token     token
     * @param userIds   用户ID SET
     * @param idCode    列表中ID的key
     * @param nameCode  列表中name的key
     * @return
     * @Function 调用用户远程服务，进行姓名填充
     * @FileName RemoteBaseServiceImpl.java
     * @MethodName matchUserName
     * @Date 2018年5月9日 上午10:33:29
     * @Author Min DongXv
     */
    @Override
    public List<EasyCreditLogEntity> matchUserNameEntity(List<EasyCreditLogEntity> entity,String token, Set<Integer> userIds) {
        if (!CollectionUtils.isEmpty(userIds)) {
            // 通过用户ID获取用户名称
            RestServiceResult<Map<String, String>> userInfo = getUserName(userIds, token);
            if (RestServiceResult.CODE_SUCCESS != userInfo.getCode()) {
                return entity;
            }
            Map<String, String> users = userInfo.getData();
            // 填充姓名信息
            for (EasyCreditLogEntity item : entity) {
                if (null != item) {
                    String userName = users.get(String.valueOf(item.getShr()));
                    if (StringUtils.isNotEmpty(userName)) {
                    	item.setShr(userName);
                    } else {
                    	item.setShr("");
                    }
                }
            }
        }
        return entity;
    }

    /**
     * @return
     * @Function 获取当前用户信息
     * @FileName RemoteBaseServiceImpl.java
     * @MethodName getCurrentUser
     * @Date 2018年5月19日 下午4:44:59
     * @Author Min DongXv
     */
    @Override
    public RestServiceResult<SysUser> getCurrentUser(String jdToken) {
        String url = urlHelper.getBaseServerUrl() + ApiPath.GET_CURRENT_USER;
        Map<String, String> params = new HashMap<String, String>(1);
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, jdToken);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<SysUser>>() {
            });
        } catch (Exception e) {
            RestServiceResult<SysUser> userData = new RestServiceResult<SysUser>();
            userData.setCode(RestServiceResult.CODE_UNKNOW);
            userData.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error(
                    "远程服务-获取当前用户信息调用异常！(XypjRemoteBaseService#getCurrentUser) URL:" + url + "Result:" + result,
                    e.getMessage(), e);
            return userData;
        }
    }

    /**
     * @param jdToken
     * @return
     * @Function 获取当前用户的所有部门信息，包括下级子部门
     * @FileName RemoteBaseServiceImpl.java
     * @MethodName getCurrentUserOffices
     * @Date 2018年5月24日 上午10:55:44
     * @Author Min DongXv
     */
    @Override
    public RestServiceResult<List<SysOfficeEntity>> getCurrentUserOffices(String jdToken) {
        String url = urlHelper.getBaseServerUrl() + ApiPath.GET_CURRENTUSER_OFFICES;
        Map<String, String> params = new HashMap<String, String>(1);
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, jdToken);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<List<SysOfficeEntity>>>() {
            });
        } catch (Exception e) {
            RestServiceResult<List<SysOfficeEntity>> officeData = new RestServiceResult<List<SysOfficeEntity>>();
            officeData.setCode(RestServiceResult.CODE_UNKNOW);
            officeData.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-获取当前用户的所有部门调用异常！(XypjRemoteBaseService#getOfficesByCurrentUser) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return officeData;
        }
    }

    @Override
    public RestServiceResult<Map<String, Object>> addWorkFlow(String wfKey, String accessKey, String userId,
                                                              String sysId, String busId, String busName, String busUrl, String busType, String remark) {
        String url = urlHelper.getBaseServerUrl() + ApiPath.WORKFLOW_ADD;
        Map<String, String> params = new HashMap<String, String>(12);
        params.put("wfKey", wfKey);
        params.put("accessKey", accessKey);
        params.put("userId", userId);
        params.put("sysId", sysId);
        params.put("busId", busId);
        params.put("busName", busName);
        params.put("busUrl", busUrl);
        params.put("busType", busType);
        params.put("remark", remark);
        String result = "";

        Map<String, String> map = new HashMap<String, String>(1);

        map.put("Content-Type", "application/json");

        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, JSON.toJSONString(params), map);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<Map<String, Object>>>() {
            });
        } catch (Exception e) {
            RestServiceResult<Map<String, Object>> data = new RestServiceResult<Map<String, Object>>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-添加工作流调用异常！(XypjRemoteBaseService#addWorkFlow) URL:" + url + " Params:"
                    + params.toString() + "Result:" + result, e.getMessage(), e);
            return data;
        }
    }

    @Override
    public RestServiceResult<Integer> getBusIdBuyTaskId(String taskId) {
        Map<String, String> params = new HashMap<String, String>(1);
        params.put("taskId", taskId);
        String url = urlHelper.getBaseServerUrl() + ApiPath.GET_BUSID_BY_TASKID;
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<Integer>>() {
            });
        } catch (Exception e) {
            RestServiceResult<Integer> data = new RestServiceResult<Integer>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-调用获取工作流异议处理业务id调用异常！(XypjRemoteBaseService#getBusIdBuyTaskId) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data;
        }
    }

    @Override
    public RestServiceResult<List<Map<String, Object>>> selectLeftTable(String tableList, String tybm) {
        Map<String, String> params = new HashMap<String, String>(1);
        params.put("tableList", tableList);
        params.put("tybm", tybm);
        String url = urlHelper.getPlatformServerUrl() + ApiPath.GET_LEFT_TABLE;
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<List<Map<String, Object>>>>() {
            });
        } catch (Exception e) {
            RestServiceResult<List<Map<String, Object>>> data = new RestServiceResult<>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-远程调用获取系统归集侧边栏信息！(XypjRemoteBaseService#selectLeftTable) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data;
        }
    }

    @Override
    public RestServiceResult checkZmtcIsExist(String ztmc, String bm, String type) {
        Map<String, String> params = new HashMap<String, String>(1);
        params.put("ztmc", ztmc);
        params.put("bm", bm);
        params.put("type", type);
        String url = urlHelper.getPlatformServerUrl() + ApiPath.CHECK_ZTMC_IS_EXIST;
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<String>>() {
            });
        } catch (Exception e) {
            RestServiceResult<String> data = new RestServiceResult<String>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-信用评价调用后台查询法人或者自然人是否存在接口异常！(XypjRemoteBaseService#checkZmtcIsExist) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data;
        }
    }

    @Override
    public List<Map> getTableValuesByTybmAndTable(String tableName, String tybm) {
        Map<String, String> params = new HashMap<String, String>(1);
        params.put("tableName", tableName);
        params.put("tybm", tybm);
        String url = urlHelper.getPlatformServerUrl() + ApiPath.GET_TABLE_VALUE;
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<List<Map>>>() {
            }).getData();
        } catch (Exception e) {
            RestServiceResult<List<Map>> data = new RestServiceResult<List<Map>>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-远程调用获取系统归集侧边栏信息！(XypjRemoteBaseService#selectLeftTable) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data.getData();
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public RestServiceResult<LinkedHashMap> getTableInfoById(String tableId, String id, String mainName) {
        Map<String, String> params = new HashMap<>(1);
        params.put("tableId", tableId);
        params.put("id", id);
        params.put("mainName", mainName);
        String url = urlHelper.getPlatformServerUrl() + "/dynamicSql/getTableInfoById.json";
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<LinkedHashMap>>() {
            });
        } catch (Exception e) {
            RestServiceResult<LinkedHashMap> data = new RestServiceResult<LinkedHashMap>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-远程调用获取系统归集侧边栏信息！(XypjRemoteBaseService#selectLeftTable) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data;
        }
    }

    @Override
    public String checkTable(String list, String tableId) {
        Map<String, String> params = new HashMap<String, String>(1);
        params.put("list", list);
        params.put("tableId", tableId);
        String url = urlHelper.getPlatformServerUrl() + ApiPath.CHECK_TABLE;
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<String>>() {
            }).getData();
        } catch (Exception e) {
            RestServiceResult<String> data = new RestServiceResult<String>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-表单校验异常！(XypjRemoteBaseService#checkTable) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data.getData();
        }
    }

    @Override
    public List<Map> getAllEnterprise(String mainType, String list, String batchId) {
        Map<String, String> params = new HashMap<String, String>(1);
        String url = urlHelper.getPlatformServerUrl() + ApiPath.GET_ALL_ENTERPRISE;
        params.put("mainType", mainType);
        params.put("list", list);
        params.put("batchId", batchId);
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<List<Map>>>() {
            }).getData();
        } catch (Exception e) {
            RestServiceResult<List<Map>> data = new RestServiceResult<List<Map>>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-远程调用获取系统归集侧边栏信息！(XypjRemoteBaseService#selectLeftTable) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data.getData();
        }
    }

    @Override
    public List<String> selectTybmByLimit(String mainType, int start, int size) {
        Map<String, String> params = new HashMap<String, String>(1);
        String url = urlHelper.getPlatformServerUrl() + ApiPath.GET_TYBM_LIMIT;
        params.put("mainType", mainType);
        params.put("start", String.valueOf(start));
        params.put("size", String.valueOf(size));
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<List<String>>>() {
            }).getData();
        } catch (Exception e) {
            RestServiceResult<List<String>> data = new RestServiceResult<List<String>>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-远程调用获取系统归集侧边栏信息！(XypjRemoteBaseService#selectLeftTable) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data.getData();
        }
    }

    @Override
    public Long selectCountAll(String mainType) {
        Map<String, String> params = new HashMap<String, String>(1);
        String url = urlHelper.getPlatformServerUrl() + ApiPath.GET_COUNT_ALL;
        params.put("mainType", mainType);
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<Long>>() {
            }).getData();
        } catch (Exception e) {
            RestServiceResult<Long> data = new RestServiceResult<Long>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-远程调用获取系统归集侧边栏信息！(XypjRemoteBaseService#selectLeftTable) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data.getData();
        }
    }

    @Override
    public String addTaskInfoForXypj(String taskName, String menuId, String taskDesc, String taskUrl, String cronExp) {
        Map<String, String> params = new HashMap<String, String>(1);
        params.put("taskName", taskName);
        params.put("menuId", menuId);
        params.put("taskDesc", taskDesc);
        params.put("taskUrl", taskUrl);
        params.put("cronExp", cronExp);
        String url = urlHelper.getBaseServerUrl() + ApiPath.ADD_XYPJ_SCH;
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<String>>() {
            }).getData();
        } catch (Exception e) {
            RestServiceResult<String> data = new RestServiceResult<String>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-远程调用获取系统归集侧边栏信息！(XypjRemoteBaseService#selectLeftTable) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data.getData();
        }
    }

    @Override
    public String updateTaskStatusForXypj(String status, String menuId, String taskUrl) {
        Map<String, String> params = new HashMap<String, String>(1);
        params.put("status", status);
        params.put("menuId", menuId);
        params.put("taskUrl", taskUrl);
        String url = urlHelper.getBaseServerUrl() + ApiPath.ADD_XYPJ_UPDATE;
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<String>>() {
            }).getData();
        } catch (Exception e) {
            RestServiceResult<String> data = new RestServiceResult<String>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-远程调用获取系统归集侧边栏信息！(XypjRemoteBaseService#selectLeftTable) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data.getData();
        }
    }

    @Override
    public List<Map> autoScoreByIndexSql(String mainType, String sql, String list, String batchId) {
        Map<String, String> params = new HashMap<String, String>(1);
        params.put("mainType", mainType);
        params.put("sql", sql);
        params.put("selectedList", list);
        params.put("batchId", batchId);
        String url = urlHelper.getPlatformServerUrl() + ApiPath.AUTO_SCORE;
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<List<Map>>>() {
            }).getData();
        } catch (Exception e) {
            RestServiceResult<List<Map>> data = new RestServiceResult<List<Map>>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-远程调用获取系统归集侧边栏信息！(XypjRemoteBaseService#selectLeftTable) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data.getData();
        }

    }

    @SuppressWarnings("unchecked")
    @Override
    public RestServiceResult<List<LinkedHashMap<String, Object>>> getIndexInfoByTybm(String relateSource, String tybm, String userId) {
        Map<String, String> params = new HashMap<String, String>(1);
        params.put("relateSource", relateSource);
        params.put("tybm", tybm);
        params.put("userId", userId);
        String url = urlHelper.getPlatformServerUrl() + ApiPath.INDEX_DATA_GET;
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<List<LinkedHashMap<String, Object>>>>() {
            });
        } catch (Exception e) {
            RestServiceResult<List<LinkedHashMap<String, Object>>> data = new RestServiceResult<>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-远程调用获取系统归集侧边栏信息！(XypjRemoteBaseService#selectLeftTable) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data;
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<String> selectBatchExport(String mainType, String batchId) {
        Map<String, String> params = new HashMap<String, String>(1);
        params.put("mainType", mainType);
        params.put("batchId", batchId);
        String url = urlHelper.getPlatformServerUrl() + ApiPath.UPLOAD_TYBM;
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<List<String>>>() {
            }).getData();
        } catch (Exception e) {
            RestServiceResult<List<String>> data = new RestServiceResult<>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-远程调用获取系统归集侧边栏信息！(XypjRemoteBaseService#selectLeftTable) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data.getData();
        }
    }

    /**
     * @param dictKey 字典主表key
     * @param dtlKey  字典值的key
     * @return
     * @Function 通过字典表ID获取特定字典表数据
     * @FileName RemoteBaseServiceImpl.java
     * @MethodName getDictByDtlKey
     * @Date 2018年6月26日 下午1:53:35
     * @Author Min DongXv
     */
    @Override
    public RestServiceResult<DictDetailEntity> getDictByDtlKey(String dictKey, String dtlKey) {
        String url = urlHelper.getBaseServerUrl() + ApiPath.GET_DICT_DETAIL;
        Map<String, String> params = new HashMap<String, String>(2);
        params.put("dictKey", dictKey);
        params.put("dtlKey", dtlKey);
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<DictDetailEntity>>() {
            });
        } catch (Exception e) {
            RestServiceResult<DictDetailEntity> data = new RestServiceResult<DictDetailEntity>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-通过字典表ID获取特定字典表数据调用异常！(RemoteBaseService#getDictByDtlKey) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data;
        }
    }

    @Override
    public RestServiceResult getValueBySql(String sql, String jdToken) {
        String url = urlHelper.getPlatformServerUrl() + ApiPath.GET_VALUE_BY_SQL;
        Map<String, String> params = new HashMap<>(2);
        params.put("sql", sql);
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<DictDetailEntity>>() {
            });
        } catch (Exception e) {
            RestServiceResult<DictDetailEntity> data = new RestServiceResult<>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-通过SQL获取数据调用异常！(RemoteBaseService#getValueBySql) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data;
        }
    }

    @Override
    public String selectTybm(String mainName) {
        String url = urlHelper.getPlatformServerUrl() + ApiPath.GET_TYBM;
        Map<String, String> params = new HashMap<>(2);
        params.put("mainName", mainName);
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<String>>() {
            }).getData();
        } catch (Exception e) {
            RestServiceResult<String> data = new RestServiceResult<>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-根据企业名获取tybm异常！(RemoteBaseService#selectTybm) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data.getData();
        }
    }

    @Override
    public List<String> selectDeleteDept() {
        String url = urlHelper.getBaseServerUrl() + ApiPath.DELETE_DEPT;
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, new HashMap<>(1), null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<List<String>>>() {
            }).getData();
        } catch (Exception e) {
            RestServiceResult<List<String>> data = new RestServiceResult<>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-远程调用已删除部门信息异常！(XypjRemoteBaseService#selectDeleteDept) URL:" + url
                    + "Result:" + result, e.getMessage(), e);
            return data.getData();
        }
    }
    
    public RestServiceResult<SysOfficeEntity> getOfficesById(long officeId){
    	String url = urlHelper.getBaseServerUrl() + ApiPath.OFFICE_BYID;
        Map<String, String> params = new HashMap<String, String>(1);
        params.put("officeId", String.valueOf(officeId));
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, null);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<SysOfficeEntity>>() {
            });
        } catch (Exception e) {
            RestServiceResult<SysOfficeEntity> officeData = new RestServiceResult<SysOfficeEntity>();
            officeData.setCode(RestServiceResult.CODE_UNKNOW);
            officeData.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-获取部门调用异常！(XypjRemoteBaseService#getOfficesById) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return officeData;
        }
    }

	@Override
	public Long getDeptIdByName(String deptName , String token) {
		String url = urlHelper.getBaseServerUrl() + ApiPath.GET_DEPT_NAME;
        Map<String, String> params = new HashMap<>(2);
        params.put("deptName", deptName);
        String result = "";
        try {
            // 发送请求
            result = HttpAgent.getInstance().sendHttpPost(url, params, token);
            return JSONObject.parseObject(result, new TypeReference<RestServiceResult<Long>>() {
            }).getData();
        } catch (Exception e) {
            RestServiceResult<Long> data = new RestServiceResult<>();
            data.setCode(RestServiceResult.CODE_UNKNOW);
            data.setMsg("系统异常，请稍后再试！");
            ExceptionLogger.error("远程服务-根据企业名获取tybm异常！(RemoteBaseService#selectTybm) URL:" + url
                    + " Params:" + params.toString() + "Result:" + result, e.getMessage(), e);
            return data.getData();
        }
	}
    
}
